#  date 2013/2/17
#  name create Joints
#  author lizhi
#  E_mail  guishiye@sina.cn
#  QQ  294596787
import maya.cmds as mc
import commonScripts02
reload(commonScripts02)
class connectSysAttr(commonScripts02.commonScripts):
    def connectBridgeAttr(self):
        if mc.objExists('Phoneme_Normal')==True :
            attrBase=['_0_neutral','_1_open_neutral','_2_AH','_3_UH','_4_EH','_5_EE','_6_OH','_7_W','_8_OO','_9_R','_10_ER','_11_YU','_12_G_K','_13_F_V','_14_bite','_15_B_M_P','_16_N_D_T','_17_L','_18_TH','_19_S','_20_SH']
            
            for atr in attrBase:
                mc.connectAttr((str('Phoneme_Normal')+'.'+atr),(str('PS_Normal_bridge')+'.'+atr))
                mc.connectAttr((str('Phonem_Smile')+'.'+atr),(str('PS_Smile_bridge')+'.'+atr))
                mc.connectAttr((str('Phonem_Frown')+'.'+atr),(str('PS_Frown_bridge')+'.'+atr))
                
    def setDKeyValue(self):
        #-----------------  facial mouth bridge ---------------------------------------
        #############################################################################################################
        ####################         jaw   ##########################################################################
        ######      open 
        openDriverAt='facial_mouth_bridge.open'
        opendrivenObj=['Jaw02_sdk']
        opendrivenV=[0,-0.3,0,20,0,0]
        opennegdrivenV=[0,0,0,-6,0,0]
        for jaw in opendrivenObj:
            self.setDrivenKey(openDriverAt,jaw,0,[0,0,0,0,0,0])
            self.setDrivenKey(openDriverAt,jaw,10,opendrivenV)
            self.setDrivenKey(openDriverAt,jaw,-10,opennegdrivenV)
            
        ######      side 
        sideDriverAt='facial_mouth_bridge.side'
        sidedrivenObj=['Jaw02_sdk']
        sidedrivenV=[0,0,0,0,10,0]
        sidenegdrivenV=[0,0,0,0,-10,0]
        for jaw in sidedrivenObj:
            self.setDrivenKey(sideDriverAt,jaw,0,[0,0,0,0,0,0])
            self.setDrivenKey(sideDriverAt,jaw,10,sidedrivenV)
            self.setDrivenKey(sideDriverAt,jaw,-10,sidenegdrivenV)
            
        ######      forward
        forwardDriverAt='facial_mouth_bridge.forward'
        forwarddrivenObj=['Jaw02_sdk']
        forwarddrivenV=[0,0,1.5,0,0,0]
        forwardnegdrivenV=[0,0,-0.7,0,0,0]
        for jaw in forwarddrivenObj:
            self.setDrivenKey(forwardDriverAt,jaw,0,[0,0,0,0,0,0])
            self.setDrivenKey(forwardDriverAt,jaw,10,forwarddrivenV)
            self.setDrivenKey(forwardDriverAt,jaw,-10,forwardnegdrivenV)
            
        ######      rotation
        rotationDriverAt='facial_mouth_bridge.rotation'
        rotationdrivenObj=['Jaw02_sdk']
        rotationdrivenV=[0,0,0,0,0,100]
        rotationnegdrivenV=[0,0,0,0,0,-100]
        for jaw in rotationdrivenObj:
            self.setDrivenKey(rotationDriverAt,jaw,0,[0,0,0,0,0,0])
            self.setDrivenKey(rotationDriverAt,jaw,10,rotationdrivenV)
            self.setDrivenKey(rotationDriverAt,jaw,-10,rotationnegdrivenV)
            
        ######      up_down
        up_downDriverAt='facial_mouth_bridge.up_down'
        up_downdrivenObj=['Jaw02_sdk']
        up_downdrivenV=[0,-3,0,0,0,0]
        up_downnegdrivenV=[0,0.7,0,0,0,0]
        for jaw in up_downdrivenObj:
            self.setDrivenKey(up_downDriverAt,jaw,0,[0,0,0,0,0,0])
            self.setDrivenKey(up_downDriverAt,jaw,10,up_downdrivenV)
            self.setDrivenKey(up_downDriverAt,jaw,-10,up_downnegdrivenV)
        ##############################################################################################################
        ####################         mouth main  ##########################################################################   
        ######      L_wide
        L_wideDriverAt='facial_mouth_bridge.L_wide'
        L_widedrivenObj=['Mouth_L_Corner_con','Mouth_L_LowLipCenter_con','Mouth_L_UpLipCenter_con','Mouth_C_UpLip_con','Mouth_C_LowLip_con','facial_L_Puffer_con', 'facial_L_Orbital_con','facial_L_Levator_con']
        L_widedrivenV=[[1.18,0,0,0,0,0],[0.435,0,0,0,0,0],[0.435,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0.36,0,0,0,0,0],[0.3,0,0,0,0,0],[0.1,0,0,0,0,0]]
        L_widenegdrivenV=[[-1.7,0,0.08,0,0,0],[-0.8,-0.05,0.25,10,-7.5,7.5],[-0.775,0.,0.25,-22,-13,-15],[0,0,0.15,0,0,0],[0,0,0.15,0,0,0],[-1.5,-0.6,1.2,0,0,0],[-0.35,-0.5,0.5,0,0,0],[0,-0.2,0,0,0,0]]
        knum=0
        for attr in L_widedrivenObj:
            self.setDrivenKey(L_wideDriverAt,attr,0,[0,0,0,0,0,0])
            self.setDrivenKey(L_wideDriverAt,attr,10,L_widedrivenV[knum])
            self.setDrivenKey(L_wideDriverAt,attr,-10,L_widenegdrivenV[knum])
            knum=knum+1
        ######      R_wide
        R_wideDriverAt='facial_mouth_bridge.R_wide'
        R_widedrivenObj=['Mouth_R_Corner_con','Mouth_R_LowLipCenter_con','Mouth_R_UpLipCenter_con','Mouth_C_UpLip_con','Mouth_C_LowLip_con','facial_R_Puffer_con', 'facial_R_Orbital_con','facial_R_Levator_con']
        R_widedrivenV=[[-1.18,0,0,0,0,0],[-0.435,0,0,0,0,0],[-0.435,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[-0.36,0,0.15,0,0,0],[-0.3,0,0,0,0,0],[-0.1,0,0,0,0,0]]
        R_widenegdrivenV=[[1.7,0,0.08,0,0,0],[0.8,-0.05,0.25,10,7.5,-7.5],[0.775,0.,0.25,-22,13,15],[0,0,0.15,0,0,0],[0,0,0.15,0,0,0],[1.5,-0.6,1.2,0,0,0],[0.35,-0.5,0.5,0,0,0],[0,-0.2,0,0,0,0]]
        knum=0
        for attr in R_widedrivenObj:
            self.setDrivenKey(R_wideDriverAt,attr,0,[0,0,0,0,0,0])
            self.setDrivenKey(R_wideDriverAt,attr,10,R_widedrivenV[knum])
            self.setDrivenKey(R_wideDriverAt,attr,-10,R_widenegdrivenV[knum])
            knum=knum+1
            
        ######      L_up_down
        L_up_downDriverAt='facial_mouth_bridge.L_up_down'
        L_up_downdrivenObj=['Mouth_L_Corner_con','Mouth_L_LowLipCenter_con','Mouth_L_UpLipCenter_con','Mouth_C_UpLip_con','Mouth_C_LowLip_con','facial_L_Puffer_con', 'facial_L_Orbital_con','facial_L_Levator_con']
        L_up_downdrivenV=[[0.3,1.4,-0.144,0,0,10],[0.12,0.3,0.04,0,0,2.5],[0.12,0.3,0,0,0,2.5],[0,0.075,0,0,0,0],[0,0.075,0,0,0,0],[0,0.08,0,0,0,0],[0,0.3,0.15,0,0,0],[-0.05,0,0,0,0,0]]
        L_up_downnegdrivenV=[[0.15,-0.9,-0.25,0,0,-7.5],[-0.025,-0.15,-0.01,0,0,-4],[0.025,-0.15,-0.01,0,0,-4],[0,-0.04,0,0,0,0],[0,-0.04,0,0,0,0],[0,-0.25,0,0,0,0],[0,-0.14,0,0,0,0],[0,0,0,0,0,0]]
        knum=0
        for attr in L_up_downdrivenObj:
            self.setDrivenKey(L_up_downDriverAt,attr,0,[0,0,0,0,0,0])
            self.setDrivenKey(L_up_downDriverAt,attr,10,L_up_downdrivenV[knum])
            self.setDrivenKey(L_up_downDriverAt,attr,-10,L_up_downnegdrivenV[knum])
            knum=knum+1
            
        ######      R_up_down
        R_up_downDriverAt='facial_mouth_bridge.R_up_down'
        R_up_downdrivenObj=['Mouth_R_Corner_con','Mouth_R_LowLipCenter_con','Mouth_R_UpLipCenter_con','Mouth_C_UpLip_con','Mouth_C_LowLip_con','facial_R_Puffer_con', 'facial_R_Orbital_con','facial_R_Levator_con']
        R_up_downdrivenV=[[-0.3,1.4,-0.144,0,0,-10],[-0.12,0.3,0.04,0,0,-2.5],[-0.12,0.3,0,0,0,-2.5],[0,0.075,0,0,0,0],[0,0.075,0,0,0,0],[0,0.08,0,0,0,0],[0,0.3,0.15,0,0,0],[0.05,0,0,0,0,0]]
        R_up_downnegdrivenV=[[-0.15,-0.9,-0.25,0,0,7.5],[0.025,-0.15,-0.01,0,0,4],[-0.025,-0.15,-0.01,0,0,4],[0,-0.04,0,0,0,0],[0,-0.04,0,0,0,0],[0,-0.25,0,0,0,0],[0,-0.14,0,0,0,0],[0,0,0,0,0,0]]
        knum=0
        for attr in R_up_downdrivenObj:
            self.setDrivenKey(R_up_downDriverAt,attr,0,[0,0,0,0,0,0])
            self.setDrivenKey(R_up_downDriverAt,attr,10,R_up_downdrivenV[knum])
            self.setDrivenKey(R_up_downDriverAt,attr,-10,R_up_downnegdrivenV[knum])
            knum=knum+1
            
        ######      Mouth_LR
        Mouth_LRDriverAt='facial_mouth_bridge.Mouth_LR'
        Mouth_LRdrivenObj=[
            'Mouth_C_All_offset',
            'Mouth_R_Corner_con',
            'Mouth_R_LowLipCenter_con',
            'Mouth_R_UpLipCenter_con',
            'Mouth_C_UpLip_con',
            'Mouth_C_LowLip_con',
            'facial_R_Puffer_con', 
            'facial_R_Orbital_con',
            'facial_R_Levator_con',
            'Mouth_L_Corner_con',
            'Mouth_L_LowLipCenter_con',
            'Mouth_L_UpLipCenter_con',
            'facial_L_Puffer_con', 
            'facial_L_Orbital_con',
            'facial_L_Levator_con']
        Mouth_LRdrivenV=[
            [0,0,0,0,12,0],
            [-0.2,0,0.45,0,-2,0],
            [-0.06,0,-0.05,0,-5,0],
            [-0.06,0,-0.05,0,-5,0],
            [0,0,0,0,0,0],
            [0,0,0,0,0,0],
            [0.15,0,0,0,10,0],
            [0.1,0,0.1,0,5,0],
            [0,0,0,0,0,0],
            [-0.25,0,-0.75,0,20,0],
            [-0.05,0,-0.325,0,16,0],
            [-0.05,0,-0.325,0,16,0],
            [0.25,0,0.05,0,0,0],
            [0.25,0,0.15,0,0,0],
            [0,0,0,0,0,0]]
        Mouth_LRnegdrivenV=[
            [0,0,0,0,-12,0],
            [0.25,0,-0.75,0,-20,0],
            [0.05,0,-0.325,0,-16,0],
            [0.05,0,-0.325,0,-16,0],
            [0,0,0,0,0,0],
            [0,0,0,0,0,0],
            [-0.25,0,0.05,0,0,0],
            [-0.25,0,0.15,0,0,0],
            [0,0,0,0,0,0],
            [0.2,0,0.45,0,2,0],
            [0.06,0,-0.05,0,5,0],
            [0.06,0,-0.05,0,5,0],
            [-0.15,0,0,0,10,0],
            [-0.1,0,0.1,0,-5,0],
            [0,0,0,0,0,0]]
        knum=0
        for attr in Mouth_LRdrivenObj:
            self.setDrivenKey(Mouth_LRDriverAt,attr,0,[0,0,0,0,0,0])
            self.setDrivenKey(Mouth_LRDriverAt,attr,10,Mouth_LRdrivenV[knum])
            self.setDrivenKey(Mouth_LRDriverAt,attr,-10,Mouth_LRnegdrivenV[knum])
            knum=knum+1
            
        ######      Mouth_UD
        Mouth_UDDriverAt='facial_mouth_bridge.Mouth_UD'
        Mouth_UDdrivenObj=['Mouth_C_All_sdk']
        Mouth_UDdrivenV=[0,1,0,0,0,0]
        Mouth_UDnegdrivenV=[0,-1.5,0,0,0,0]
        for jaw in Mouth_UDdrivenObj:
            self.setDrivenKey(Mouth_UDDriverAt,jaw,0,[0,0,0,0,0,0])
            self.setDrivenKey(Mouth_UDDriverAt,jaw,10,Mouth_UDdrivenV)
            self.setDrivenKey(Mouth_UDDriverAt,jaw,-10,Mouth_UDnegdrivenV)
            
        ######      Mouth_FB
        Mouth_FBDriverAt='facial_mouth_bridge.Mouth_FB'
        Mouth_FBdrivenObj=['Mouth_C_All_sdk']
        Mouth_FBdrivenV=[0,0,1.5,0,0,0]
        Mouth_FBnegdrivenV=[0,0,-1.5,0,0,0]
        for jaw in Mouth_FBdrivenObj:
            self.setDrivenKey(Mouth_FBDriverAt,jaw,0,[0,0,0,0,0,0])
            self.setDrivenKey(Mouth_FBDriverAt,jaw,10,Mouth_FBdrivenV)
            self.setDrivenKey(Mouth_FBDriverAt,jaw,-10,Mouth_FBnegdrivenV)
            
        ######      Mouth_Rot_X
        Mouth_Rot_XDriverAt='facial_mouth_bridge.Mouth_Rot_X'
        Mouth_Rot_XdrivenObj=['Mouth_C_All_sdk']
        Mouth_Rot_XdrivenV=[0,0,0,100,0,0]
        Mouth_Rot_XnegdrivenV=[0,0,0,-100,0,0]
        for jaw in Mouth_Rot_XdrivenObj:
            self.setDrivenKey(Mouth_Rot_XDriverAt,jaw,0,[0,0,0,0,0,0])
            self.setDrivenKey(Mouth_Rot_XDriverAt,jaw,100,Mouth_Rot_XdrivenV)
            self.setDrivenKey(Mouth_Rot_XDriverAt,jaw,-100,Mouth_Rot_XnegdrivenV)
            
        ######      Mouth_Rot_Y
        Mouth_Rot_YDriverAt='facial_mouth_bridge.Mouth_Rot_Y'
        Mouth_Rot_YdrivenObj=['Mouth_C_All_sdk']
        Mouth_Rot_YdrivenV=[0,0,0,0,100,0]
        Mouth_Rot_YnegdrivenV=[0,0,0,0,100,0]
        for jaw in Mouth_Rot_YdrivenObj:
            self.setDrivenKey(Mouth_Rot_YDriverAt,jaw,0,[0,0,0,0,0,0])
            self.setDrivenKey(Mouth_Rot_YDriverAt,jaw,100,Mouth_Rot_YdrivenV)
            self.setDrivenKey(Mouth_Rot_YDriverAt,jaw,-100,Mouth_Rot_YnegdrivenV)
            
        ######      Mouth_Rot_Z
        Mouth_Rot_ZDriverAt='facial_mouth_bridge.Mouth_Rot_Z'
        Mouth_Rot_ZdrivenObj=['Mouth_C_All_sdk']
        Mouth_Rot_ZdrivenV=[0,0,0,0,0,100]
        Mouth_Rot_ZnegdrivenV=[0,0,0,0,0,-100]
        for jaw in Mouth_Rot_ZdrivenObj:
            self.setDrivenKey(Mouth_Rot_ZDriverAt,jaw,0,[0,0,0,0,0,0])
            self.setDrivenKey(Mouth_Rot_ZDriverAt,jaw,100,Mouth_Rot_ZdrivenV)
            self.setDrivenKey(Mouth_Rot_ZDriverAt,jaw,-100,Mouth_Rot_ZnegdrivenV)
        
        ######      C_up_lip_roll
        C_up_lip_rollDriverAt='facial_mouth_bridge.C_up_lip_roll'
        C_up_lip_rolldrivenObj=['Mouth_C_UpLip_con','Mouth_L_UpLipCenter_con','Mouth_R_UpLipCenter_con']
        C_up_lip_rolldrivenV=[[0,0.5,0.6,-40,0,0.15],[0,0.35,0.5,-40,2,-6],[0,0.35,0.5,-40,-2,-6]]
        C_up_lip_rollnegdrivenV=[[0,-0.05,-0.25,70,0,0],[0,-0.15,-0.3,40,5,4.5],[0,-0.15,-0.3,40,-5,4.5]]
        knum=0
        for attr in C_up_lip_rolldrivenObj:
            self.setDrivenKey(C_up_lip_rollDriverAt,attr,0,[0,0,0,0,0,0])
            self.setDrivenKey(C_up_lip_rollDriverAt,attr,10,C_up_lip_rolldrivenV[knum])
            self.setDrivenKey(C_up_lip_rollDriverAt,attr,-10,C_up_lip_rollnegdrivenV[knum])
            knum=knum+1
            
        ######      C_low_lip_roll
        C_low_lip_rollDriverAt='facial_mouth_bridge.C_low_lip_roll'
        C_low_lip_rolldrivenObj=['Mouth_C_LowLip_con','Mouth_L_LowLipCenter_con','Mouth_R_LowLipCenter_con']
        C_low_lip_rolldrivenV=[[0,-0.05,0.2,40,0,0],[0,-0.2,0.2,30,2,2],[0,-0.2,0.2,30,-2,-2]]
        C_low_lip_rollnegdrivenV=[[0,0.02,-0.27,-20,0,0],[0,0.05,-0.05,-28,0,0],[0,0.05,-0.05,-28,0,0]]
        knum=0
        for attr in C_low_lip_rolldrivenObj:
            self.setDrivenKey(C_low_lip_rollDriverAt,attr,0,[0,0,0,0,0,0])
            self.setDrivenKey(C_low_lip_rollDriverAt,attr,10,C_low_lip_rolldrivenV[knum])
            self.setDrivenKey(C_low_lip_rollDriverAt,attr,-10,C_low_lip_rollnegdrivenV[knum])
            knum=knum+1
        #-----------------  facial mouth bridge ---------------------------------------
        #############################################################################################################
        ####################         jaw   ##########################################################################
        ######      facial_L_eyeCenter_sdk
        L_UpEyelid_closeDriverAt='facials_eyes_bridge.L_UpEyelid_close'
        L_UpEyelid_closedrivenObj=['facial_L_eyeCenter_sdk']
        L_UpEyelid_closedrivenV=[[0,0,0,33,0,0]]
        L_UpEyelid_closenegdrivenV=[[0,0,0,-33,0,0]]
        knum=0
        for attr in L_UpEyelid_closedrivenObj:
            self.setDrivenKey(L_UpEyelid_closeDriverAt,attr,0,[0,0,0,0,0,0])
            self.setDrivenKey(L_UpEyelid_closeDriverAt,attr,10,L_UpEyelid_closedrivenV[knum])
            self.setDrivenKey(L_UpEyelid_closeDriverAt,attr,-10,L_UpEyelid_closenegdrivenV[knum])
            knum=knum+1